//
//  WarnListDetailsTableViewCell.m
//  YuTang
//
//  Created by 葛悦彣 on 2025/4/2.
//

#import "WarnListDetailsTableViewCell.h"

@interface WarnListDetailsTableViewCell ()

@property (nonatomic ,strong) UILabel * alarmContent;
@property (nonatomic ,strong) UILabel * status;
@property (nonatomic ,strong) UIView * pondView;
@property (nonatomic ,strong) UILabel * pondLab;
@property (nonatomic ,strong) UILabel * createTime;
@property (nonatomic ,strong) UILabel * alarmDegree_dictText;



@end


@implementation WarnListDetailsTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setupView];
    }
    return self;
}


- (void)setupView{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    self.userInteractionEnabled = YES;
    self.contentView.userInteractionEnabled = YES;
    self.contentView.clipsToBounds = YES;

    UIView * backview = [UIView new];
    backview.backgroundColor = UIColor.whiteColor;
    [self.contentView addSubview:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.offset(0);
        make.bottom.offset(kwt(-10));
    }];
    
    UILabel * alarmContent = [DTKTool labelWithText:@"-" andFont:kCFont(18) andTextColor:KcolorHex(@"#222222")];
    self.alarmContent = alarmContent;
    [backview addSubview:alarmContent];
    [alarmContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.top.offset(kwt(16));
        make.height.offset(kwt(18));
    }];
    
    
    UILabel * status = [DTKTool labelWithText:@"-" andFont:kFont(16) andTextColor:KcolorHex(@"#FE5402")];
    status.backgroundColor = KcolorHex(@"#FFE8DD");
    status.textAlignment = NSTextAlignmentCenter;
    [DTKTool BFYJ:kwt(7) andView:status andCorner:UIRectCornerBottomLeft|UIRectCornerBottomRight andSize:CGRectMake( 0, 0,kwt(70), kwt(27))];
    self.status = status;
    [backview addSubview:status];
    [status mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-5));
        make.top.offset(0);
        make.width.offset(kwt(70));
        make.height.offset(kwt(27));
    }];
    
    UIView * line = [UIView new];
    line.backgroundColor = KcolorHex(@"#D8D8D8");
    [backview addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-12));
        make.top.offset(kwt(44));
        make.left.offset(kwt(12));
        make.height.offset(0.5);
    }];
    
    UIView * pondView = [UIView new];
    self.pondView = pondView;
    [backview addSubview:pondView];
    [pondView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.equalTo(line.mas_bottom);
        make.height.offset(kwt(25));
    }];
    
    UILabel * pondLab = [DTKTool labelWithText:@"-" andFont:kFont(15) andTextColor:KcolorHex(@"#222222")];
    self.pondLab = pondLab;
    pondLab.numberOfLines = 0;
    [pondView addSubview:pondLab];
    [pondLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(kwt(350));
        make.bottom.offset(0);
        make.left.offset(kwt(12));
    }];
    
    UILabel * temp1 = [DTKTool labelWithText:@"告警时间：" andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
    [backview addSubview:temp1];
    [temp1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(pondView.mas_bottom).offset(kwt(10));
        make.left.offset(kwt(12));
        make.height.offset(kwt(15));
    }];
    
    UILabel * createTime = [DTKTool labelWithText:@"-" andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
    self.createTime = createTime;
    [backview addSubview:createTime];
    [createTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(temp1.mas_right);
        make.centerY.equalTo(temp1);
    }];
    
    
    UILabel * temp2 = [DTKTool labelWithText:@"告警程度：" andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
    [backview addSubview:temp2];
    [temp2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(temp1.mas_bottom).offset(kwt(10));
        make.left.offset(kwt(12));
        make.height.offset(kwt(15));
    }];
    
    UILabel * alarmDegree_dictText = [DTKTool labelWithText:@"-" andFont:kFont(15) andTextColor:KcolorHex(@"#FE5402")];
    self.alarmDegree_dictText = alarmDegree_dictText;
    [backview addSubview:alarmDegree_dictText];
    [alarmDegree_dictText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(temp2.mas_right);
        make.centerY.equalTo(temp2);
    }];
        
    
}

- (void)setModel:(WarnModel *)model {
    _model = model;
    self.alarmContent.text = model.alarmContent;
    self.status.text = model.status_dictText;
    ///处理状态 0.待处理 1.已处理
    if(model.status == 0){
        self.status.textColor = KcolorHex(@"#FE5402");
        self.status.backgroundColor = KcolorHex(@"#FFE8DD");
    } else if(model.status == 1){
        self.status.textColor = KcolorHex(@"#0967FF");
        self.status.backgroundColor = KcolorHex(@"#D7E2FB");
    }
    
    self.pondLab.text = model.tissueListStr;
//    self.pondLab.text = [NSString stringWithFormat:@"%@ %@", model.pondTissues.firstObject.pondTissue,model.pondTissues.firstObject.pondName];
    [self.pondView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.offset(model.pondViewH);
    }];
    
    self.createTime.text = model.createTime;
    self.alarmDegree_dictText.text = model.alarmDegree_dictText;
}
@end
